import * as THREE from '../../build/three.module.js';
import {
  OrbitControls
} from '../../jsm/controls/OrbitControls.js'

const scene = new THREE.Scene();

/**
 * 构架几何体
 */
const p1 = new THREE.Vector3(-85.35, -35.36, 20);
const p2 = new THREE.Vector3(-50, 0, 50);
const p3 = new THREE.Vector3(0, 50, -50);
const p4 = new THREE.Vector3(50, 0, 50);
const p5 = new THREE.Vector3(85.35, -35.36, -20);
// 创建一条直线
const line1 = new THREE.LineCurve3(p1, p2);
// 创建一个三维样条曲线
const crc = new THREE.CatmullRomCurve3([p2, p3, p4]);
// 创建直线
const line2 = new THREE.LineCurve3(p4, p5);

// 创建组合曲线
const curvePath = new THREE.CurvePath();
curvePath.curves.push(line1, crc, line2);

// 通过曲线路径（组合曲线）创建管道
const tubeGeo = new THREE.TubeGeometry(curvePath, 100, 5, 25, false);
const tubeMat = new THREE.MeshBasicMaterial({
  color: 0x0000aa,
  side: THREE.DoubleSide
});
const meshTube = new THREE.Mesh(tubeGeo, tubeMat);
scene.add(meshTube);

// 其他要素
const ambientL = new THREE.AmbientLight(0x444444);
scene.add(ambientL);
const axesH = new THREE.AxesHelper(200);
scene.add(axesH);
const k = innerWidth / innerHeight,
      s = 60,
      camera = new THREE.PerspectiveCamera(s, k, 1, 1000);
camera.position.set(400, 400, 400);
camera.lookAt(scene.position);

const renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0xaaaaaa);
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);

new OrbitControls(camera, renderer.domElement);

function render() {
  requestAnimationFrame(render);
  renderer.render(scene, camera);
}
render();